<?php
session_start();
include "Includes/solotrn_sesion.php";
include "Includes/soloFun_Generales.php";
require_once "config.php";
require_once "Includes/conexion.class.php";
//printArray($_SESSION);
$sql2 = "select active_directory from solotb_usuario_infoadic where nu_usua like '%". $_SESSION["id_usua"] ."%'";
$actived = EjecutaSentenciaSql($sql2);

if ($_REQUEST["txtCodigo"] <> "") {
    $arrQueries = array();
    $tabla = "solotb_usuario";
    $tipo = "UPDATE";
    $strSql = "$tipo $tabla set cl_usua= '" . $_REQUEST["ATxtClave"] . "' where nu_usua=" . $_SESSION["id_usua"];
    $strSql .= " and nodo=".$_SESSION["empresa"];
    array_push($arrQueries, $strSql);
    array_push($arrQueries, crearQueryLog($tabla, $tipo, $strSql));

    $oConexion = new Conexion($WORKFLOW["motor_base"], $WORKFLOW["db_usuario"], $WORKFLOW["db_password"], 
            $WORKFLOW["basedatos"], $WORKFLOW["servidor"], $WORKFLOW["flags"], $WORKFLOW["encoding"]);
    //if(!$oConexion->EjecutarQuery($strSql))
    if(!$oConexion->EjecutarTransaccion($arrQueries))
        header("Location: solotrn_CambiarClaveUsuario.php?SoloError=1");
    else
        header("Location: solotrn_CambiarClaveUsuario.php?SoloError=0");

    $oConexion->Cerrar();
}
//print_r($_SESSION);
?>
<html>
    <head>
        <title>SoloPortal - Cambiar Clave</title>
        <meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1">
        <link rel="stylesheet" href="SoloStyles/Solostyles.css" type="text/css">
        <SCRIPT type="text/JavaScript" src="Includes/Solofun_generales.js"></SCRIPT>
    </head>

    <body topmargin="0" leftmargin="0">
        <p align="center" class="SoloStyle_TituloPaginas">Cambiar Clave Usuario</p>
        <br>
        <form name="frmIngreso" action="solotrn_CambiarClaveUsuario.php" method="POST">
            <table border="0" width="60%" align="center" cellpadding="2" cellspacing="1" bordercolor="#CCCCCC">
                <tr>
                    <td>
                        <img src="iconos/soloico_seguridad.gif" border="1" alt="Cambiar Clave Usuario" style="cursor:hand" onClick="ValidaDatos();" >
                    </td>
            </table>
            <table border="1" width="60%" cellpadding="2" cellspacing="2" bordercolor="#CCCCCC" align="center">
                <tr>
                    <td class="SoloStyle_Etiqueta" width="30%"><b>Id</b> </td>
                    <td class="SoloStyle_Grid" width="70%"><?php echo $_SESSION["id_usua"];?>
                        <input type="hidden" name="txtCodigo" value="<?php echo $_SESSION["id_usua"];?>"></td>
                </tr>
                <tr>
                    <td class="SoloStyle_Etiqueta"><b>Nombre</b> </td>
                    <td class="SoloStyle_Grid"><?php echo $_SESSION["no_usua"];?></td>
                </tr>
                <tr>
                    <td class="SoloStyle_Etiqueta"><b>Usuario</b> </td>
                    <td class="SoloStyle_Grid"> <?php echo $_SESSION["co_usua"];?></td>
                </tr>
                <tr>
                    <td class="SoloStyle_Etiqueta"><b>Perfil</b> </td>
                    <td class="SoloStyle_Grid"><?php echo $_SESSION["ds_perf"];?></td>
                </tr>
                <tr>
                    <td class="SoloStyle_Etiqueta"><b>Nueva Clave</b> </td>
                    <td class="SoloStyle_Grid">
                        <input name="ATxtClave" id="ATxtClave" type="password" class="SoloStyle_Texto" size="20" maxlength="10"   <?php if ($actived == "S") {?> disabled="disabled" <?php }?> >
                    </td>
                </tr>
                <tr>
                    <td class="SoloStyle_Etiqueta"><b>Repetir Clave</b> </td>
                    <td class="SoloStyle_Grid">
                        <input name="ATxtClave2" id="ATxtClave2" type="password" class="SoloStyle_Texto" size="20" maxlength="10"   <?php if ($actived == "S") {?> disabled="disabled" <?php }?> >
                    </td>
                </tr>
            </table>
            <script type="text/javaScript">
                function ValidaDatos(){
                    if (document.getElementById("ATxtClave").value == ""){
                        alert("El campo es requerido");
                        document.getElementById("ATxtClave").focus();
                        return false;
                    }
                    if (document.getElementById("ATxtClave2").value == ""){
                        alert("El campo es requerido");
                        document.getElementById("ATxtClave2").focus();
                        return false;
                    }

                    if (document.getElementById("ATxtClave2").value.length < 5){
                        alert("La Longitud de la clave debe ser mayor a 5");
                        document.getElementById("ATxtClave").focus();
                        return false;
                    }

                    if (document.getElementById("ATxtClave").value != document.getElementById("ATxtClave2").value){
                        alert("Las Claves son Diferentes");
                        document.getElementById("ATxtClave").focus();
                    }else{
                        document.frmIngreso.submit();
                    }
                }

            </script>
        </form>
    </body>
</html>
<?php
include "Includes/soloFun_ShowMessages.php";
?>
